﻿//************************************************************************************************************
// CoNatural.Threading.dll
// Author: Roger Torres
//************************************************************************************************************
// You can use, modify, and distribute the source code and executable programs based on the source code.
// This source code is provided "as is" and without warranties as to performance or merchantability. 
// The author and/or distributors of this source code may have made statements about this source code. 
// Any such statements do not constitute warranties and shall not be relied on by the user in deciding 
// whether to use this source code. This source code is provided without any express or implied warranties 
// whatsoever. Because of the diversity of conditions and hardware under which this source code may be used, 
// no warranty of fitness for a particular purpose is offered. The user is advised to test the source code 
// thoroughly before relying on it. The user must assume the entire risk of using the source code.
//************************************************************************************************************

using System;

namespace CoNatural.Threading.Async {
   /// <summary>
   /// Asynchronous action's event arguments
   /// </summary>
	public class AsyncActionEventArgs : EventArgs {
      /// <summary>
      /// The source action.
      /// </summary>
		public AsyncAction Action { get; private set; }

      /// <summary>
      /// The managed thread id where the event was raised.
      /// </summary>
		public int ManagedThreadId { get; private set; }

		internal AsyncActionEventArgs(AsyncAction action, int managedThreadId) {
			Action = action;
			ManagedThreadId = managedThreadId;
		}
	}

   /// <summary>
   /// Completed event arguments.
   /// </summary>
	public class AsyncActionCompletedEventArgs : AsyncActionEventArgs {
      /// <summary>
      /// True if the action was cancelled, False otherwise.
      /// </summary>
		public bool Cancelled { get; private set; }

      /// <summary>
      /// Exception raised when the action failed, Null otherwise.
      /// </summary>
		public AsyncActionException Error { get; private set; }

		internal AsyncActionCompletedEventArgs(AsyncAction action, int managedThreadId, bool cancelled, AsyncActionException error)
			: base(action, managedThreadId) {
			Cancelled = cancelled;
			Error = error;
		}
	}

   /// <summary>
   /// Progress event arguments.
   /// </summary>
	public class AsyncActionProgressChangedEventArgs : AsyncActionEventArgs {
      /// <summary>
      /// The progress percentage.
      /// </summary>
		public int ProgressPercentage { get; private set; }

		internal AsyncActionProgressChangedEventArgs(AsyncAction action, int managedThreadId, int progressPercentage)
			: base(action, managedThreadId) {
			ProgressPercentage = progressPercentage;
		}
	}

   /// <summary>
   /// Trace event arguments.
   /// </summary>
	public class AsyncActionTracedEventArgs : AsyncActionEventArgs {
      /// <summary>
      /// The trace message.
      /// </summary>
		public string Message { get; private set; }

		internal AsyncActionTracedEventArgs(AsyncAction action, int managedThreadId, string message)
			: base(action, managedThreadId) {
			Message = message;
		}
	}
}
